/**
 * 
 */
package cn.edu.hstc.ui.fragment;

import android.net.http.AndroidHttpClient;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import cn.edu.hstc.app.App;
import cn.edu.hstc.bean.ScheduleTable;
import cn.edu.hstc.bean.ScheduleTable.Course;
import cn.edu.hstc.bean.utils.ScheduleUtils;
import cn.edu.hstc.common.HttpUtils;
import cn.edu.hstc.common.L;
import cn.edu.hstc.ui.JwglMain;
import cn.edu.hstc.ui.LoginJwgl;

/**
 * @Description 用户课程表展示
 * @author act262
 * @version 1.0
 * @since 2014-4-30 下午5:34:11
 * 
 */
public class UserSchedule extends BaseFragment {

	private AndroidHttpClient mHttpClient;
	private static UserSchedule sFragment = null;

	private final String TAG = UserSchedule.class.getSimpleName();

	/**
	 * @param bundle
	 * @return
	 */
	public static UserSchedule getInstance(Bundle bundle) {
		if (null == sFragment) {
			sFragment = new UserSchedule();
		}
		sFragment.setArguments(bundle);
		return sFragment;
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		L.d(TAG, "onCreate");
		new GetScheduleTask().execute(App.getUser().getStudentId(), App.getUser().getName());
	}

	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	private final class GetScheduleTask extends AsyncTask<String, Integer, ScheduleTable> {

		protected ScheduleTable doInBackground(String... params) {
			return ScheduleUtils.getSchedule(JwglMain.sHttpClient, params);
		}

		protected void onPreExecute() {
			super.onPreExecute();
			L.d(TAG, "GetScheduleTask start");
		}

		protected void onPostExecute(ScheduleTable result) {
			super.onPostExecute(result);
			L.d(TAG, "GetScheduleTask end");
			if (null != result) {
				Course[][] list = result.getCourseList();
				for (int i = 0; i < list.length; i++) {
					for (int j = 0; j < list[i].length; j++) {
						System.out.println(list[i][j]);
					}
				}
			}
		}

	}
}
